unit ufrmStorage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ufrmChildOne, cxTL,
  cxEdit, DB, cxDBData, DBClient,
  Provider, ADODB, DosMove, Menus, ExtCtrls, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, cxInplaceContainer, cxTLData, cxDBTL, cxPC,
  StdCtrls, RzPanel, RzSplit, ufmeUserInfo, Mask, DBCtrls, uPubDeclare,
  cxGraphics, cxCustomData, cxStyles, cxFilter, cxData, cxDataStorage;

type
  TfrmStorage = class(TfrmChildOne)
    adsDataSTORAGE_ID: TLargeintField;
    adsDataSTORAGE_NM: TStringField;
    adsDataZJM: TStringField;
    adsDataADD_USER: TLargeintField;
    adsDataADD_TIME: TDateTimeField;
    adsDataEDIT_USER: TLargeintField;
    adsDataEDIT_TIME: TDateTimeField;
    cdsDataSTORAGE_ID: TLargeintField;
    cdsDataSTORAGE_NM: TStringField;
    cdsDataZJM: TStringField;
    cdsDataADD_USER: TLargeintField;
    cdsDataADD_TIME: TDateTimeField;
    cdsDataEDIT_USER: TLargeintField;
    cdsDataEDIT_TIME: TDateTimeField;
    cxgrdbtblvwTreeSTORAGE_ID: TcxGridDBColumn;
    cxgrdbtblvwTreeSTORAGE_NM: TcxGridDBColumn;
    cxgrdbtblvwTreeZJM: TcxGridDBColumn;
    fmeUserInfo1: TfmeUserInfo;
    lblSTORAGE_NM: TLabel;
    dbedtSTORAGE_NM: TDBEdit;
    lblZJM: TLabel;
    dbedtZJM: TDBEdit;
    procedure dbedtSTORAGE_NMChange(Sender: TObject);
    procedure cdsDataAfterOpen(DataSet: TDataSet);
  private
    { Private declarations }
    fStorageID: Int64;
  protected
    procedure doQuery; override;
    procedure doAfterOperate(Operate: TOperateState); override;
  public
    { Public declarations }  
    function CanOperate(AOperate: TOperateState): Boolean; override;
  end;

var
  frmStorage: TfrmStorage;

implementation

uses uPubFuncs;

{$R *.dfm}

{ TfrmStorage }

function TfrmStorage.CanOperate(AOperate: TOperateState): Boolean;
begin
  Result := inherited CanOperate(AOperate);
end;

procedure TfrmStorage.doAfterOperate(Operate: TOperateState);
begin
  inherited;
  SetWriteable(dbedtSTORAGE_NM);
  SetWriteable(dbedtZJM);
  case Operate of
    mAdd: cdsDataSTORAGE_ID.AsInteger := GetNextID('GEN_STORAGE');
  end;
end;

procedure TfrmStorage.doQuery;
begin
  inherited;
  cdsData.Close;
  adsData.Close;
  adsData.CommandText :=
    'select * from storage ' +
    ' where storage_nm like ''%'+edtSearch.Text+'%'' ' +
    ' order by storage_id';
  cdsData.Open;
end;

procedure TfrmStorage.dbedtSTORAGE_NMChange(Sender: TObject);
begin
  inherited;
  if (OperateState in [mAdd, mEdit]) and (cdsData.State in [dsInsert, dsEdit]) then
    cdsDataZJM.AsString := GetPYIndexStr(Copy(dbedtSTORAGE_NM.Text, 1, 10));
end;

procedure TfrmStorage.cdsDataAfterOpen(DataSet: TDataSet);
begin
  inherited;
  fmeUserInfo1.cdsAddUser.Open;
end;

initialization
  RegisterClass(TfrmStorage);
finalization
  UnRegisterClass(TfrmStorage);

end.
